package com.kr.aia.powerrp.roleplay;
 
import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;

import com.kr.aia.powerrp.R;
 
public class RPDataDeleteListAdapter extends ArrayAdapter<RPDataVO> {
 
    private Context context;
    private int layoutResourceId;
    private ArrayList<RPDataVO> data;
    
    private int curPosition = -1;
 
    public RPDataDeleteListAdapter(Context context, int layoutResourceId, ArrayList<RPDataVO> d) {
    	super(context, layoutResourceId, d);
    	this.context = context;
    	this.layoutResourceId = layoutResourceId;
        this.data=d;
    }
 
    public int getCount() {
        return data.size();
    }
     
    public void setSelectedItem(int position){
    	this.curPosition = position;
    }
    
    public int getSelectedItem(){
    	return this.curPosition;
    }
    
    public long getItemId(int position) {
        return position;
    }
 
    public View getView(int position, View convertView, ViewGroup parent) {
        View vi=convertView;
        if(vi == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            vi = inflater.inflate(layoutResourceId, parent, false);
        }
        
        
        RPDataVO curItem = super.getItem(position);
        if(curItem != null){
            TextView rp_file_name = (TextView)vi.findViewById(R.id.rp_file_name); // title
            CheckBox rp_file_name_checkbox = (CheckBox)vi.findViewById(R.id.rp_file_name_checkbox); // title
            rp_file_name.setText(curItem.getTitle());

            if(curItem.isSelected){
            	vi.setBackgroundResource(R.drawable.gradient_bg_hover);
            	rp_file_name_checkbox.setChecked(true);
            }else{
            	vi.setBackgroundResource(R.drawable.gradient_bg);
            	rp_file_name_checkbox.setChecked(false);
            }
        }
        return vi;
    }
}